﻿using FarseerPhysics.Dynamics.Contacts;
using IcicleFramework.Components.Physics;
using IcicleFramework.GameServices;
using IcicleFramework.Physics;

namespace IcicleFramework.Components.Behaviors.CollisionBehaviors
{
    public abstract class PhysicsCollisionBehavior : BaseBehavior
    {
        protected PhysicsCollisionBehavior() { }

        protected PhysicsCollisionBehavior(PhysicsCollisionBehavior old)
            : base(old) { }

        public override void Initialize()
        {
            //Tell the collision manager we want to subscribe...
            IPhysicsManager collisionManager = GameServiceManager.GetService<IPhysicsManager>();

            if (collisionManager != null)
                collisionManager.SubscribeCollisionEvent(this.ParentGameObject.GUID, OnCollision);

            base.Initialize();
        }

        protected abstract void OnCollision(IPhysicsComponent physicsComponent, IPhysicsComponent colliding, Contact contact);
    }
}
